{php include wl_template('common/header');}
<div class="panel panel-info">
	<div class="panel-heading">添加阶梯团</div>
	<div class="panel-body">
		<form action="" method="post" class="form-horizontal">
			{if empty($goodsid)}
			<div class="form-group">
				<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">选择商品</label>
				 <div class="col-xs-12 col-sm-4 col-md-4 col-lg-8">
					<select name="goodsid" class="form-control select" id="test" onchange="selectChange();">
						<option value="" {if empty($_GPC['merchantid'])}selected="selected"{/if}>--选择--</option>
						{loop $data['list'] $row}
				            <option value="{$row['id']}" {if $_GPC['goodsid']==$row['id']}selected="selected"{/if} >{$row['gname']}</option>
						{/loop}
			        </select>
				</div>
			</div>
			<div class="panel panel-default" id="show" style="display: none;">
				<div class="table-responsive">
					<table class="table table-hover">
						<thead>
						<tr>
							<th style="width:80px;">商品图</th>
							<th style="width:180px;">商品名</th>
						</tr>
						</thead>
						<tbody>
						<tr data-toggle="popover" data-trigger="hover" data-placement="left" class="js-goods-img">
							<td><img class="scrollLoading2" id="img"  src=""  height="50" width="50"/></td>
							<td class="line-feed" id="gname">
								{php echo cutstr($goods['gname'], 30, true);}
							</td>
						</tr>
						</tbody>
					</table>
				</div>
			</div>
			{else}
			<div class="panel panel-default">
				<div class="table-responsive">
					<table class="table table-hover">
						<thead>
						<tr>
							<th style="width:80px;">商品图</th>
							<th style="width:180px;">商品名</th>
							<th class="text-center" style="width:120px;">所属商家</th>
						</tr>
						</thead>
						<tbody>
						<tr data-toggle="popover" data-trigger="hover" data-placement="left" class="js-goods-img">
							<td><img class="scrollLoading" src="{IMAGE_PIXEL}" data-url="{$goods['gimg']}" onerror="this.src='{IMAGE_NOPIC_SMALL}'" height="50" width="50"/></td>
							<td class="line-feed">
								{php echo cutstr($goods['gname'], 30, true);}
							</td>
							<td class="text-center">
								<span class="">{if empty($goods['merchant']['name'])}{$_W['account']['name']}{else}{$goods['merchant']['name']}{/if}</span>
							</td>
						</tr>
						</tbody>
					</table>
				</div>
			</div>
			{$pager}
			<style>
			.inner__content {background: #eee none repeat scroll 0 0;border-top: 1px solid #dcdcdc;box-sizing: border-box;color: #666;margin-top: 10px;margin-bottom:10px;min-width: 100%;padding: 10px 5px;width: auto;text-align:center;}
			</style>
			<script>
			
			$(function(){
					$(".scrollLoading").scrollLoading();
					var $pop = null;
					$('.scrollLoading').hover(function(){
						var img = $(this).attr('src');
						var obj = this;
						var $pop = util.popover(obj, function($popover, obj){
							obj.$popover = $popover;
						}, '<div><img src="'+img+'" style="max-width:200px; max-height:200px;"></div>');
					}, function(){
						this.$popover.remove();
					});
				});
			</script>
			{/if}
			<div class="form-group">
				<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">开启阶梯</label>
				<div class="col-xs-12 col-sm-8">
					<label class="radio radio-inline">
						<input type="radio" name="group_level_status" value="1" {if intval($goods['group_level_status']) ==1 }checked="checked"{/if} onclick="$('#level').hide();"> 不开启
					</label>
					<label class="radio radio-inline">
						<input type="radio" name="group_level_status" value="2" {if intval($goods['group_level_status']) ==2 || empty($goods['group_level_status'])}checked="checked"{/if} onclick="$('#level').show();"> 开启
					</label>
					<div class="col-sm-9 col-xs-12">
					<span class="help-block">(启用阶梯团后，商品规格将失效，商品的价格及库存以阶梯团为准)</span>
				</div>
				</div>
			</div>
			<div class="form-group" id="level">
				<div class="col-xs-12 col-sm-4 col-md-4 col-lg-12">
					<div class="panel-body table-responsive" style="padding:0px;">
						<table class="table table-hover">
							<thead>
							<tr>
								<th></th>
								<th>几人</th>
								<th>团购价(单位：元)</th>
							</tr>
							</thead>
							<tbody id="param-items-level">
								{loop $group_level $item}
								<tr>
									<td>
										<a href="javascript:;" class="fa fa-move" title="拖动调整此显示顺序"><i class="fa fa-arrows"></i></a>&nbsp;
										<a href="javascript:;" onclick="deleteParam_level(this)" style="margin-top:10px;" title="删除"><i class='fa fa-remove'></i></a>
									</td>
									<td>
										<input name="param_groupnum[]" type="text" class="form-control param_title" value="{$item['groupnum']}"/>
									</td>
									<td><input name="param_groupprice[]" type="text" class="form-control param_value" value="{$item['groupprice']}"/></td>
								</tr>
								{/loop}
							</tbody>
							
							<tbody>
								<tr>
									<td colspan="3">
										<a href="javascript:;" id='add-param' onclick="addParam_level()" style="margin-top:10px;"  title="添加阶梯">添加阶梯 <i class='fa fa-plus'></i></a>
									</td>
								</tr>
							</tbody>
						</table>
					</div>
				</div>
			</div>
			<div class="form-group col-sm-12">
				<input type="hidden" name="id" value="{$goods['id']}" />
				<input type="submit" name="submit" value="提交" class="btn btn-primary col-lg-1" />
				<input type="hidden" name="token" value="{$_W['token']}" />
			</div>
		</form>
	</div>
</div>
	<script language="javascript">
	function selectChange(){
		var s = document.getElementById("test");
        var v = s.options[s.selectedIndex].value;
        var ajaxurl = "{php echo web_url('application/ladder/ajax')}";
        $.ajax({
				type: "POST",
				url: ajaxurl,
				data:{id:v},
				dataType: 'json',
				beforeSend: function(XMLHttpRequest) {},
				success: function(data) {
					$('#show').show();
					$('#img').attr("src",data.gimg);
					$('#gname').html(data.gname);
					
				},
				error:function(){alert("商品信息错误!");}
			});
	} 
	$(function(){
		$("#chkoption").click(function(){
			var obj =$(this);
			if(obj.get(0).checked){
				$("#tboption").show();
				$(".trp").hide();
			}
			else{
				$("#tboption").hide();
				$(".trp").show();
			}
		});
	})
	function addParam_level() {
		var data = '';
			data += '<tr>'
						+'<td>'
							+'<a href="javascript:;" class="fa fa-move" title="拖动调整此显示顺序"><i class="fa fa-arrows"></i></a>&nbsp;'
							+'<a href="javascript:;" onclick="deleteParam_level(this)" style="margin-top:10px;"  title="删除"><i class="fa fa-times"></i></a>'
						+'</td>'
						+'<td>'
							+'<input name="param_groupnum[]" type="text" class="form-control param_title" value=""/>'
						+'</td>'
						+'<td><input name="param_groupprice[]" type="text" class="form-control param_value" value=""/></td>'
					+'</tr>';
		$('#param-items-level').append(data);
	}
	function deleteParam_level(o) {
		$(o).parent().parent().remove();
	}
</script>
{php include wl_template('common/footer');}